﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using yncTech.BusinessObjects;
using System.Data;

public partial class Admin_Fin_Fin002 : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtStartDate.Value = DateTime.Now.AddMonths(-1).Date.ToString(ConstantValue.DateFormat);
            txtEndate.Value = DateTime.Now.ToString(ConstantValue.DateFormat);
            if (Session["sd"] != null)
            {
                txtStartDate.Value = Session["sd"].ToString();
            }
            if (Session["ed"] != null)
            {
                txtEndate.Value = Session["ed"].ToString();
            }
        }

    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Session["sd"] = txtStartDate.Value;
        Session["ed"] = txtEndate.Value;
    }


    protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
    {
        VBoxReceiptsCollection receipts = new VBoxReceiptsCollection();

        receipts.Query.Where(receipts.Query.CreatedDttm >= txtStartDate.Value && receipts.Query.CreatedDttm <= DateTime.Parse(txtEndate.Value).AddDays(1));

        if (!LoginUserInfo.CurrentUser.IsAdmin)
        {
            receipts.Query.Where(receipts.Query.BoxLocation == LoginUserInfo.CurrentUser.ThirdUnitID);
        }
        receipts.Query.OrderBy(receipts.Query.CreatedDttm.Descending);

        pageGrid.DataSource = receipts.Query.LoadDataTable();
        pageGrid.CurrentPage = e.NewPageIndex;
        pageGrid.DataBind();
    }

    protected override void OnUnload(EventArgs e)
    {
        base.OnUnload(e);
        Session.Remove("sd");
        Session.Remove("ed");
      
    }

    protected string GetActionUrl(string status, object rowView, int receiptCount)
    {
        string retUrl = "";

        if (status.Equals(ConstantValue.StorageStatusCode.InStock))
        {
            retUrl = GetLink("添加凭证", "A", "Fin002c.aspx", rowView, 980, 580, false, VBoxReceiptsMetadata.ColumnNames.BoxID);
            retUrl += "   " + GetUpdateLink("Fin002a.aspx", rowView, 680, 580, VBoxReceiptsMetadata.ColumnNames.BoxID);
            if (receiptCount > 0)
            {
                retUrl += "   " + GetLink("标签打印", "A", "Fin002d.aspx", rowView, 1200, 740, false, VBoxReceiptsMetadata.ColumnNames.BoxID);
            }

        }

        return retUrl;
    }
}